package drive.Service.ServiceFormat;

import com.google.gson.Gson;
import drive.Mapper.RoadDisasterMapper;
import drive.Model.RoadDisaster;
import drive.Service.ServiceInterface.RoadDisasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoadDisasterServiceA implements RoadDisasterService {

    @Autowired
    private RoadDisasterMapper roadDisasterMapper;

    private Gson gson = new Gson();

    @Override
    public String findAll() {
        List<RoadDisaster> list = roadDisasterMapper.findAll();
        return gson.toJson(list);
    }

    @Override
    public String findByDisasterID(Integer disasterID) {
        RoadDisaster roadDisaster = roadDisasterMapper.findByDisasterID(disasterID);
        return gson.toJson(roadDisaster);
    }

    @Override
    public String findByUserID(Integer userID) {
        List<RoadDisaster> list = roadDisasterMapper.findByUserID(userID);
        return gson.toJson(list);
    }

    @Override
    public String add(RoadDisaster roadDisaster) {
        int result = roadDisasterMapper.add(roadDisaster);
        return "添加灾害信息成功";
    }

    @Override
    public String update(RoadDisaster roadDisaster) {
        int result = roadDisasterMapper.update(roadDisaster);
        return "更新灾害信息成功";
    }

    @Override
    public String delete(Integer disasterID) {
        int result = roadDisasterMapper.delete(disasterID);
        return "删除灾害信息成功";
    }
}